#include "HttpServer.hpp"
#include"HttpProtocol.hpp"
#include"Log.hpp"
using namespace LogModule;
void Login(HttpRequest&req,HttpResponse&res)
{

    LOG(LogLevel::INFO)<<"进入登录模块"<<req.Path()<<"   "<<req.Args();
    std::string req_args=req.Args();
    //解析参数格式，得到的参数
    res.SetCode(200);
    std::string body=req.GetContent("wwwroot/success.html"); 
    res.SetBody(body);
    res.SetHeader("Content-Length",std::to_string(body.size()));
    res.SetHeader("Content-Type","text/html");
    res.SetHeader("Set-Cookie","pssswd=123456;");
    res.SetHeader("Set-Cookie","username=zs;");
    //访问数据库，验证该用户账号密码是否合法
    // res.SetCode(302);
    // res.SetHeader("Location","/");//重定向到首页
    //登录成功


}

void Register(HttpRequest&req,HttpResponse&res)
{
    LOG(LogLevel::INFO)<<"进入注册模块"<<req.Path()<<"   "<<req.Args();
}

void Search(HttpRequest&req,HttpResponse&res)
{
    LOG(LogLevel::INFO)<<"进入搜索模块"<<req.Path()<<"   "<<req.Args();
}

void Test(HttpRequest&req,HttpResponse&res)
{
    LOG(LogLevel::INFO)<<"进入测试模块"<<req.Path()<<"   "<<req.Args();
}
int main()
{
auto httpserver=std::make_unique<HttpServer>(8082);
//给服务器登录功能
httpserver->Register("/login",Login);//restful风格的网络接口
httpserver->Register("/register",Register);
httpserver->Register("/search",Search);
httpserver->Register("/test",Test);
httpserver->Start();

}
